package com.ruoyi.web.controller;

import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.system.domain.Athlete;
import com.ruoyi.system.service.IAthleteService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.stream.Collectors;

/**
 * @author Ly lilongfei
 * @date 2024/8/26
 * @Description
 */
@RestController
public class AthleteController {

    @Autowired
    private IAthleteService athleteService;

    /**
     * 根据教练id查询运动员
     * @param coachId
     * @return
     */
    @PostMapping("/findAthleteByCoach")
    public AjaxResult findAthleteByCoach(Integer coachId){
        List<Athlete> athleteList = athleteService.findAthleteByCoach(coachId);
        if(athleteList.isEmpty()){
            throw new RuntimeException("未查询到运动员,请确认教练Id");
        }
        //去重
        List<Athlete> uniqueList = athleteList.stream().distinct().collect(Collectors.toList());
        return AjaxResult.success(uniqueList);
    }

}
